<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="档案大类" >
              <j-dict-select-category v-model="queryParam.archiveMajorCategory" placeholder="请选择档案大类" parentCode="A04" removeCode="A04A02,A04A01" :async="true" @input="modifyCategory"/>
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="档案小类">
              <j-dict-select-category :disabled="!queryParam.archiveMajorCategory" v-model="queryParam.archiveMinorCategory" placeholder="请选择档案小类" :parentCode="queryParam.archiveMajorCategory" :async="true"/>
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="档案编号">
              <j-input placeholder="请输入档案编号" v-model="queryParam.fileNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目编号">
              <j-input placeholder="请输入项目编号" v-model="queryParam.projectNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <j-input placeholder="请输入项目名称" v-model="queryParam.projectName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="项目负责人">
              <select-user-by-dep
                v-model="queryParam.projectLeader"/>
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="档案所属团队">
              <select-team-input
                v-model="queryParam.archiveBelongingTeam"
                :teamType="0"
                :tdlx="1"
              />
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="签订单位">
              <select-Company-input  v-model="queryParam.signUnit" placeholder="请选择签订单位" />
            </a-form-model-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
              <!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
              <!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
              <!--              </a>-->
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleMultiEdit" type="primary" icon="plu">批量编辑</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('项目存档清单')" :disabled="isDisabledAuth('erpProjectArchiveFile:export')">导出</a-button>
      <!--<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpProjectArchiveFile:import')">导入</a-button>
      </a-upload>
      -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
<!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpProjectArchiveFile:delete')"><a-icon type="delete"/>删除</a-menu-item>-->
<!--        </a-menu>-->
<!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
<!--      </a-dropdown>-->
<!--      <a-popover title="自定义列" trigger="click" placement="leftBottom">-->
<!--        <template slot="content">-->
<!--          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">-->
<!--            <a-row>-->
<!--              <template v-for="(item,index) in defColumns">-->
<!--                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">-->
<!--                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>-->
<!--                </template>-->
<!--              </template>-->
<!--            </a-row>-->
<!--          </a-checkbox-group>-->
<!--        </template>-->
<!--        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>-->
<!--      </a-popover>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"

        @change="handleTableChange">
<!--        <a slot="billNo" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a>-->
        <a slot="projectArchive" slot-scope="text, record" @click="goProjectArchiveDetail(record.billId)">{{ text }}</a>
        <a slot="projectId" slot-scope="text, record" @click="onDetail(record.projectId)">{{ text }}</a>
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
            <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="edit"
                @click="handleEdit(record)"
                :disabled="isDisabledAuth('erpProjectArchiveFile:edit')"
        />
        </span>

      </a-table>
    </div>

    <!-- 批量编辑弹窗 -->
    <a-modal v-model="editFlag" title="批量编辑" width="1200px" @ok="editOk" :bodyStyle ="{
        'height':'350px',
      }">
      <j-form-container >
        <a-form-model ref="form" :model="archiveFileModel" :rules="validatorRules" slot="detail">
          <a-row :gutter="48" >
            <a-col :span="8">
              <a-form-model-item label="存档时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="archiveTime">
                <j-date :show-time="true"
                        date-format="YYYY-MM-DD HH:mm:ss"
                        placeholder="请选择存档时间"
                        v-model="archiveFileModel.archiveTime"
                        style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="档案闭合时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fileCloseTime">
                <j-date :show-time="true"
                        date-format="YYYY-MM-DD HH:mm:ss"
                        placeholder="请选择档案闭合时间"
                        v-model="archiveFileModel.fileCloseTime"
                        style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="存档人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="archivePerson">
                <select-user-by-dep   :multi="false" v-model="archiveFileModel.archivePerson"></select-user-by-dep>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="接收人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiver">
                <select-user-by-dep   :multi="false" v-model="archiveFileModel.receiver"></select-user-by-dep>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="存档位置" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="archiveLocation">
                <a-input  v-model="archiveFileModel.archiveLocation" :max-length="36"  placeholder="请输入存档位置"  ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="8"></a-col>
          </a-row>
        </a-form-model>
      </j-form-container>
    </a-modal>


    <a-modal
      :maskClosable="false"
      title="项目存档申请单详情"
      :width="1200"
      :bodyStyle="{
            padding: '0 24px'
          }"
      :visible="visibleDetail"
      @cancel="handleCancelDetail"
      cancelText="关闭">
      <erp-project-archive-form ref="realForm" :disabled="true" normal />
      <template slot="footer">
        <a-button @click.stop="handleCancelDetail">关闭</a-button>
      </template>
    </a-modal>

    <!-- 项目详情开始 -->
    <erp-project-report-modal  ref="projectModalForm"></erp-project-report-modal>
    <!-- 项目详情结束 -->

    <erp-project-archive-file-modal ref="modalForm" @ok="modalFormOk"></erp-project-archive-file-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ErpProjectArchiveFileModal from './modules/ErpProjectArchiveFileModal'
  import { getAction,postAction,httpAction } from '@/api/manage'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import ErpProjectArchiveForm from './modules/ErpProjectArchiveForm.vue';
  import JDictSelectCategory from '@/components/dict/JDictSelectCategory.vue'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import ErpProjectReportModal from '@/views/erp/report/project/modules/ErpProjectReportModal'


  export default {
    name: 'ErpProjectArchiveFileList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpProjectArchiveForm,
      ErpProjectArchiveFileModal,
      SelectUserByDep,
      JDictSelectCategory,
      SelectTeamInput,
      SelectCompanyInput,
      ErpProjectReportModal
    },
    data () {
      return {
        description: '项目存档清单管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        visibleDetail: false,
        editFlag: false,
        archiveFileModel: {
          archiveTime: null,
          fileCloseTime: null,
          archivePerson: null,
          receiver: null,
          archiveLocation: null,
        },
        /* 排序参数 */
        isorter: {
          column: 'createTime',
          order: 'desc'
        },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        validatorRules: {
          archiveTime: [
            { required: true, message: '请选择存档时间!' }
          ],

          fileCloseTime: [
            { required: true, message: '请选择档案闭合时间!' }
          ],
          archivePerson: [
            { required: true, message: '请选择存档人!' }
          ],
          receiver: [
            { required: true, message: '请选择接收人!' }
          ],
          archiveLocation: [
            { required: true, message: '请输入存档位置!'}
          ],
        },
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'档案大类',
            align:"center",
            dataIndex: 'archiveMajorCategory_dictText',
            ellipsis: true,
            width: 200,
          },
          {
            title:'档案小类',
            align:"center",
            dataIndex: 'archiveMinorCategory_dictText',
            ellipsis: true,
            width: 200,
          },
          {
            title:'档案编号',
            align:"center",
            dataIndex: 'fileNo',
            scopedSlots: { customRender: 'projectArchive' },
            ellipsis: true,
            width: 200,
          },
          {
            title:'项目编号',
            align:"center",
            dataIndex: 'projectNo',
            ellipsis: true,
            width: 200,
          },
          {
            title:'项目名称',
            align:"center",
            dataIndex: 'projectId_dictText',
            scopedSlots: { customRender: 'projectId' },
            ellipsis: true,
            width: 200,
          },
          {
            title:'签订单位',
            align:"center",
            dataIndex: 'signUnit_dictText',
            ellipsis: true,
            width: 200,
          },
          {
            title:'项目负责人',
            align:"center",
            dataIndex: 'projectLeader_dictText',
            ellipsis: true,
            width: 200,
          },

          {
            title:'密级',
            align:"center",
            dataIndex: 'secrecyLevel_dictText',
            ellipsis: true,
            width: 200,
          },

          {
            title:'档案所属团队',
            align:"center",
            dataIndex: 'archiveBelongingTeam_dictText',
            ellipsis: true,
            width: 200,
          },
          // {
          //   title:'业务名称',
          //   align:"center",
          //   dataIndex: 'businessName_dictText',
          //   ellipsis: true,
          // },

          {
            title:'存档时间',
            align:"center",
            dataIndex: 'archiveTime',
            ellipsis: true,
            width: 200,
            customRender:function (text) {
              // return !text?"":(text.length>10?text.substr(0,10):text)
              return !text?"":text
            }
          },
          {
            title:'档案闭合时间',
            align:"center",
            dataIndex: 'fileCloseTime',
            ellipsis: true,
            width: 200,
            customRender:function (text) {
              // return !text?"":(text.length>10?text.substr(0,10):text)
              return !text?"":text
            }
          },
          {
            title:'存档人',
            align:"center",
            dataIndex: 'archivePerson_dictText',
            ellipsis: true,
            width: 200,
          },
          {
            title:'接收人',
            align:"center",
            dataIndex: 'receiver_dictText',
            ellipsis: true,
            width: 200,
          },
          {
            title:'存档位置',
            align:"center",
            dataIndex: 'archiveLocation',
            ellipsis: true,
            width: 200,
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remarks',
            ellipsis: true,
            width: 200,
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:160,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: "/api/erp/omc/projectarchive/erpProjectArchiveFile/list",
          delete: "/api/erp/omc/projectarchive/erpProjectArchiveFile/delete",
          deleteBatch: "/api/erp/omc/projectarchive/erpProjectArchiveFile/deleteBatch",
          editBatch: "/api/erp/omc/projectarchive/erpProjectArchiveFile/editBatch",
          exportXlsUrl: "/api/erp/omc/projectarchive/erpProjectArchiveFile/exportXls",
          importExcelUrl: "/api/erp/omc/projectarchive/erpProjectArchiveFile/importExcel",
          queryProjectArchive: "/api/erp/omc/projectarchive/erpProjectArchive/queryById",
          // 穿透项目名称
          queryProjectById: '/api/erp/project/report/erpProjectReport/queryById',
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      //查看详情
      // getDetail(id) {
      //   this.$router.push({
      //     path: `/erp/前端路径/参数`,
      //   })
      // },
      //修改大类，清空小类
      modifyCategory(data){
        if(data){
          if(this.queryParam.archiveMinorCategory){
            this.$set(this.queryParam,"archiveMinorCategory",null);
          }
        }
      },
      goProjectArchiveDetail(id){
        this.$nextTick(()=>{
          getAction(this.url.queryProjectArchive, { id }).then((res) => {
            if (res.success) {
              this.visibleDetail = true
              const model = res.result
              this.$nextTick(()=>{
                this.$refs.realForm.edit(model);
              });
            }
          })
        });
      },

      onDetail(id) {
        const that = this
        this.$nextTick(() => {
          getAction(this.url.queryProjectById, { id }).then((res) => {
            if (res.success) {
              const model = res.result
              that.$refs.projectModalForm.getDetail(model);
              that.$refs.projectModalForm.title = '项目一览表';
            }
          })
        })
      },
      handleCancelDetail() {
        this.visibleDetail = false
        this.$set(this.archiveFileModel,'archiveTime',null)
        this.$set(this.archiveFileModel,'fileCloseTime',null)
        this.$set(this.archiveFileModel,'archivePerson',null)
        this.$set(this.archiveFileModel,'receiver',null)
        this.$set(this.archiveFileModel,'archiveLocation',null)

      },
      handleMultiEdit(){

        this.editFlag = true
        this.$refs['form'].clearValidate();
        this.$set(this.archiveFileModel,'archiveTime',null)
        this.$set(this.archiveFileModel,'fileCloseTime',null)
        this.$set(this.archiveFileModel,'archivePerson',null)
        this.$set(this.archiveFileModel,'receiver',null)
        this.$set(this.archiveFileModel,'archiveLocation',null)
      },
      editOk(){
        const that = this;


        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！')
        } else {
          var ids = ''
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ','
          }

          let model = JSON.parse(JSON.stringify(this.archiveFileModel));
          model.ids = ids
          that.loading = true
          // 触发表单验证
          this.$refs.form.validate(valid => {
              if (valid) {
                httpAction(this.url.editBatch,model,'put').then((res)=>{
                  if(res.success){
                    that.editFlag = false
                    that.$message.success(res.message);
                    that.onClearSelected()
                    that.loadData()
                  }else{
                    that.$message.warning(res.message);
                  }
                }).finally(() => {
                  that.loading = false
                })
              }else{
                that.loading = false
              }
          })

        }


      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'archiveMajorCategory',text:'档案大类',dictCode:''})
        fieldList.push({type:'string',value:'fileNo',text:'档案编号',dictCode:''})
        fieldList.push({type:'string',value:'billId',text:'项目存档申请id',dictCode:''})
        fieldList.push({type:'string',value:'billNo',text:'项目存档申请编号',dictCode:''})
        fieldList.push({type:'string',value:'projectId',text:'项目id',dictCode:''})
        fieldList.push({type:'string',value:'projectNo',text:'项目编号',dictCode:''})
        fieldList.push({type:'string',value:'projectName',text:'项目名称',dictCode:''})
        fieldList.push({type:'string',value:'signUnit',text:'签订单位',dictCode:''})
        fieldList.push({type:'string',value:'archiveBelongingTeam',text:'档案所属团队',dictCode:''})
        fieldList.push({type:'string',value:'businessName',text:'业务名称',dictCode:''})
        fieldList.push({type:'string',value:'archiveMinorCategory',text:'档案小类',dictCode:''})
        fieldList.push({type:'string',value:'projectLeader',text:'项目负责人',dictCode:''})
        fieldList.push({type:'string',value:'secrecyLevel',text:'密级',dictCode:''})
        fieldList.push({type:'date',value:'archiveTime',text:'存档时间'})
        fieldList.push({type:'date',value:'fileCloseTime',text:'档案闭合时间'})
        fieldList.push({type:'string',value:'archivePerson',text:'存档人',dictCode:''})
        fieldList.push({type:'string',value:'receiver',text:'接收人',dictCode:''})
        fieldList.push({type:'Text',value:'archiveLocation',text:'存档位置',dictCode:''})
        fieldList.push({type:'Text',value:'remarks',text:'备注',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
